home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18334 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  86 lines

  1. Path: news.tiac.net!usenet
  2. From: edickau@highground.com (Ellen L. Dickau)
  3. Newsgroups: comp.lang.c++
  4. Subject: VC++ 4.1 virtual destructors and wrong delete oper
  5. Date: 20 Apr 1996 00:05:57 GMT
  6. Organization: HighGround Systems, Inc.
  7. Message-ID: <4l99p5$88s@news.tiac.net>
  8. NNTP-Posting-Host: 205.161.49.141
  9. Mime-Version: 1.0
  10. Content-Type: Text/Plain; charset=US-ASCII
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13.  
  14. I have version 4.1 of MS Visual C++ and I am seeing the following problem 
  15. which is documented as fixed in MS Visual C++ 4.0.  The problem has to do with 
  16. virtual destructors in a class that is exported from a DLL (when you call 
  17. delete on the class the wrong delete operator is called if the class has a 
  18. virtual destructor).  Can anyone confirm that this problem has reappeared in 
  19. 4.1? 
  20.  
  21. The workaround described in the article makes the problem go away, but I'd 
  22. still like acknowledgement that the problem is there and I am trying this 
  23. newsgroup until the microsoft news groups become available. 
  24.  
  25. thanks,
  26. -Ellen Dickau
  27.  
  28. Here is the initial part of the Microsoft documentation of the problem:
  29.  
  30. PSS ID Number: Q122675
  31. Article last modified on 01-19-1996
  32.  
  33. 7.00   | 1.00 1.50 1.51 1.52 | 1.00 2.00 2.10 2.20
  34.  
  35. MS-DOS | WINDOWS             | WINDOWS NT
  36.  
  37.  
  38. ----------------------------------------------------------------------
  39. The information in this article applies to:
  40.  
  41.  - The Microsoft C/C++ compiler (CL.EXE), included with:
  42.  
  43.     - Microsoft C/C++ for MS-DOS, version 7.0
  44.     - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52
  45.     - Microsoft Visual C++, 32-bit Edition, versions 1.0, 2.0, 2.1,
  46.       and 2.2
  47. ----------------------------------------------------------------------
  48.  
  49. SYMPTOMS
  50. ========
  51.  
  52. When allocating and deleting an object of a class that is exported from a
  53. DLL, you may find that the new operator in the EXE is called to allocate
  54. the memory but the delete operator in the DLL is called to delete the
  55. memory. Therefore, there is a new/delete mismatching problem, which may
  56. cause run-time errors.
  57.  
  58. CAUSE
  59. =====
  60.  
  61. This problem is a result of the way objects are allocated, constructed,
  62. destructed and deallocated. The following things occur when allocating
  63. and deallocating objects that have constructors and destructors:
  64.  
  65. Allocating:
  66.  
  67.    A1. The memory that the object will reside in is allocated.
  68.    A2. The appropriate constructor for that object is called.
  69.  
  70. Deallocating:
  71.  
  72.    D1. The destructor for the object is called.
  73.    D2. If the object is being deallocated via delete, call delete.
  74.  
  75. Step D2 is where the problem arises for objects created from classes
  76. exported from a DLL. Steps D1 and D2 are often carried out by a scalar or
  77. vector deleting destructor, which is a helper function generated at compile
  78. time. When this helper function is created in the DLL, any calls it makes
  79. to the delete operator will be in the context of the DLL. Therefore the
  80. delete operator overridden in the EXE will not be called as expected.....
  81.  
  82.  
  83.  
  84. ....
  85.  
  86.